import request from '@/utils/request'

// 分页查询课程信息
export type TQueryCondition = {
  currentPage?: number
  pageSize?: number
  courseName?: string
  status?: number | ''
}
export interface TCoursesResult {
  records: TCourseItem[]
  total: number
  size: number
  current: number
  pages: number
}

interface TCourseItem {
  id: number
  courseName: string
  price: string
  sortNum: number
}
export const getQueryCourses = (queryCondition: TQueryCondition) => {
  return request<Common<TCoursesResult>>({
    method: 'POST',
    url: 'boss/course/getQueryCourses',
    data: { queryCondition }
  })
}

// 课程上下架

// 保存或更新课程信息
export interface TCourse {
  id?: number
  courseName: string
  brief: string
  teacherDTO: TeacherDTO
  previewFirstField: string
  previewSecondField: string
  sortNum: number
  discounts: number
  price: number
  sales: number
  discountsTag: string
  courseListImg: string
  courseImgUrl: string
  activityCourse: boolean
  activityCourseDTO: ActivityCourseDTO
  courseDescriptionMarkDown: string
  status: number
}

interface ActivityCourseDTO {
  beginTime: string
  endTime: string
  amount: number
  stock: number
}

interface TeacherDTO {
  id: number
  courseId: number
  teacherName: string
  teacherHeadPicUrl: string
  position: string
  description: string
}
export const saveOrUpdateCourse = (course: TCourse) => {
  return request<Common<boolean>>({
    method: 'POST',
    url: 'boss/course/saveOrUpdateCourse',
    data: course
  })
}

// 获取指定ID课程的信息
export const getCourseById = (courseId: number) => {
  return request<Common<TCourse>>({
    method: 'GET',
    url: '/boss/course/getCourseById',
    params: { courseId }
  })
}
// 指定课程-获取所有章节-课时
export interface TSection {
  id: number
  courseId: number
  sectionName: string
  description: string
  createTime: string
  updateTime: string
  isVisible: boolean
  isDe: boolean
  orderNum: number
  lastOperatorId?: any
  lessonDTOS: LessonDTO[]
  status: number
}

interface LessonDTO {
  id: number
  courseId: number
  sectionId: number
  theme: string
  duration: number
  durationNum: number
  isFree: boolean
  startImgUrl: string
  orderNum: number
  status: number
  isTimingPublish: boolean
  publishTime: string
  fileId: number
}
export const getSectionAndLesson = (courseId: number) => {
  return request<Common<TSection[]>>({
    method: 'GET',
    url: '/boss/course/section/getSectionAndLesson',
    params: { courseId }
  })
}

// 章节 添加或编辑
